import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default {
    state: {
        //菜单栏收缩标志
        isCollapse: false,
        //菜单数据
        menuList: [
            {
                children: [],
                icon: "el-icon-copy-document",
                label: "住户资料管理",
                name: "HouseholdManage",
                path: "/householdManage",
                url: "/householdManage/HouseholdManage",
            },
            {
                children: [],
                icon: "el-icon-copy-document",
                label: "投诉管理",
                name: "ComplaintManage",
                path: "/complaintManage",
                url: "complaintManage/ComplaintManage",
            },
            {
                children: [],
                icon: "el-icon-copy-document",
                label: "报修管理",
                name: "RepairServiceManage",
                path: "/repairServiceManage",
                url: "/repairServiceManage/RepairServiceManage",
            },
            {
                children: [],
                icon: "el-icon-copy-document",
                label: "缴费管理",
                name: "PayFeesManage",
                path: "/payFeesManage",
                url: "/payFeesManage/PayFeesManage",
            },
            {
                children: [],
                icon: "el-icon-copy-document",
                label: "停车位管理",
                name: "PackingSpaceManage",
                path: "/packingSpaceManage",
                url: "/packingSpaceManage/PackingSpaceManage",
            },
            {
                children: [],
                icon: "el-icon-copy-document",
                label: "疫情防控",
                name: "COVID19Condition",
                path: "/covid19Condition",
                url: "/covid19Condition/COVID19Condition",
            },
        ],
        //当前激活的选项卡
        editableTabsValue: 'Home',
        //选项卡数据
        editableTabs: [
            {
                title: '首页',
                name: 'Home'
            }
        ]
    },
    mutations: {
        setMenuBarOpenOrClose(state) {
            state.isCollapse = !state.isCollapse;
        },
        //菜单点击时候调用
        selectMenu(state, val) {
            console.log(val);
            //1.把当前点击的菜单，加到选项卡里面
            let res = state.editableTabs.findIndex(item => item.name === val.name);
            //2.判断选项卡是否存在，不存在才加入到选项卡
            if (res === -1) {
                let obj = {};
                obj.title = val.label;
                obj.name = val.name;
                state.editableTabs.push(obj);
            }
            //3、设置当前激活的选项卡
            state.editableTabsValue = val.name;
            //4、暂存选项卡
            sessionStorage.setItem('tabsList', JSON.stringify(state.editableTabs));
        },
        //设置选项卡
        getTabs(state) {
            let tabsList = sessionStorage.getItem('tabsList');
            if (tabsList) {
                state.editableTabs = JSON.parse(tabsList);
            }
        },
        //设置当前激活的选项卡
        setActiveTabs(state, val) {
            state.editableTabsValue = val;
        }
    },
    actions: {
    }
}